import { tab } from '@testing-library/user-event/dist/tab'
import React from 'react'

export default function List({ projects, param, users }) {
  if (projects === null) {
    return "加载中。。。"
  }
  if(param.projectName )
  return (
    <div>
      <table border="1">
        <thead>
          <tr>
            <th>项目</th>
            <th>负责人</th>
          </tr>
        </thead>
        {
          (param.personId === null || param.personId === 0)
            ?
            (
              projects.filter(project => project.name.includes(param.projectName)).length !== 0
                ?
                projects.filter(project => project.name.includes(param.projectName))?.map((project) => (
                  <tbody key={project.id}>
                    <tr>
                      <td>{project.name}</td>
                      <td>{users.find(user => user.id === project.personId).name}</td>
                    </tr>
                  </tbody>
                ))
                :
                <tbody>
                  <tr>
                    <td colSpan="2">搜索中。。。</td>
                  </tr>
                </tbody>
            )
            :
            (
              param.projectName === ""
                ?
                projects.filter(project => project.personId === param.personId)?.map((project) => (
                  <tbody key={project.id}>
                    <tr>
                      <td>{project.name}</td>
                      <td>{users.find(user => user.id === param.personId).name}</td>
                    </tr>
                  </tbody>
                ))
                :
                (
                  projects.filter(project => project.name.includes(param.projectName)).length !== 0
                    ?
                    projects.filter(project => project.name.includes(param.projectName))?.map((project) => (
                      <tbody key={project.id}>
                        <tr>
                          <td>{project.name}</td>
                          <td>{users.find(user => user.id === project.personId).name}</td>
                        </tr>
                      </tbody>
                    ))
                    :
                    <tbody>
                      <tr>
                        <td colSpan="2">搜索中。。。</td>
                      </tr>
                    </tbody>
                )
            )
        }
      </table>
    </div>
  )
}
